import React, { Component } from 'react';
import { Button, Card, Col, Row } from 'antd';
import moment from 'moment';
import { fetchData, getWmsRestRoot } from '../../components/AjaxConsumer'

const tracking_print_button = {
    position: 'fixed',
    right: '10%',
    top: '20px',
}

let time = null;

export default class PrintBarCodePage extends Component {

    constructor(props) {
        super(props);
        this.state = {
            codeList: ['BM03H1EA50HSIK7H0001', 'BM03H1EA50HSIK7H0002'], //条码列表
            dataList: [],
            isPrint: true
        }
    }


    componentDidMount() {
        $("body").removeClass("baseWidthSet");
        // const { list } = this.props.location.state;
        // list.map((item,index)=>{
        //   this.createBarcode(this[`barcode_${index}`],item);
        // })

        const userDefined2 = this.props.location.query.userDefined2;
        console.log(userDefined2);
        const options = {
            url: '/product/probarcode/getPtintInfo?userDefined2=' + userDefined2,
            type: 'get',
            condition: {}
        };
        fetchData(this, options, (res) => {
            //回调函数
            const pagination = { ...this.state.pagination };
            pagination.total = res.data.totalCount;
            console.log(res.data);
            this.setState({
                dataList: res.data,
            });
        })

    }


    print = () => {
        //document.getElementsByTagName("body").classList.remove("baseWidthSet");
        this.setState({ isPrint: false }, () => {
            //document.body.innerHTML=document.getElementById('div1').innerHTML;

            window.print();
            this.setState({ isPrint: true });
        });
    }

    render() {
        const { dataList, isPrint } = this.state;
        const list = [1];//this.props.location.state;
        return (
            <div id='div1'>
                {
                    isPrint ?
                        (
                            <div style={tracking_print_button}>
                                <Button type="primary" onClick={this.print}>打印</Button>
                            </div>
                        )
                        : null
                }
                {

                    dataList.map((item, index) => {
                        return (
                            <div className="print-barcode-page" key={index}>

                                <div className="barcode-page-subpage-table">
                                    <table>
                                        <colgroup width="21%" align="center"></colgroup>
                                        <colgroup width="42%" align="right"></colgroup>
                                        <colgroup width="17%" align="center"></colgroup>
                                        <colgroup width="20%" align="right"></colgroup>
                                        <tr>
                                            <td>零件料号:</td>
                                            <td colSpan="3"></td>
                                        </tr>
                                        <tr>
                                            <td>零件名称:</td>
                                            <td colSpan="3"></td>
                                        </tr>
                                        <tr>
                                            <td>工程编号:</td>
                                            <td></td>
                                            <td>数量:</td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td>机型:</td>
                                            <td></td>
                                            <td>台份:</td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td>预入库号:</td>
                                            <td></td>
                                            <td>订货号:</td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td>原文料号:</td>
                                            <td colSpan="3"></td>
                                            
                                        </tr>
                                        <tr>
                                        <td align="center" colSpan="2" style={{ paddingLeft: "0.1cm", paddingBottom: "0" }}>
                                                <div className="barcode-subpage-text">

                                                    <div className="text-cell">
                                                        {/* <p>{item.kdOrderNo}_{item.onlineOrderNo}</p>
                                                        <p>{item.barcodeNumber}_{item.controlType}{item.userDefined1}</p> */}
                                                    </div>
                                                                                  
                                                </div>
                                            </td>
                                            <td colSpan="2" style={{ textAlign: "center" }}>                                  
                                                <p>沪东重机有限公司</p>
                                            </td>
                                            
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        )
                    })


                }
            </div>

        )
    }
}
